const oss_domain = getApp().globalData.oss_domain
const parameter = getApp().globalData.parameter
const domainName = getApp().globalData.domainName

  // 加载机构信息
const jg_homePage_init=(that,jg_id)=>{
    wx.request({
      url: domainName + '/jg_homePage_init',
      data: {
        jg_id:jg_id,
      },...parameter,
      success: res => {
        // console.log('jg_info',res.data.jg_info)
        that.setData({
          jg_operation_btns:res.data.jg_operation_btns,
          jg_info:res.data.jg_info,
        })
      },
    })
  }

const operation_btn=(that, e)=>{
  let btn_id = e.currentTarget.id

  // 更新点击次数
  update_jg_btn_count(that, btn_id)

  if(btn_id==1){
    var url = '/pages/jgs/service_tel/service_tel?jg_id=' + that.jg_id + '&service_tel_list=' + encodeURIComponent(JSON.stringify(that.data.jg_info.service_tel_list))
  }else if(btn_id==2){
    var url = '/pages/jgs/jg_shortName/jg_shortName?jg_id=' + that.jg_id + '&jg_name=' + that.data.jg_info.jg_name + '&short_name=' + that.data.jg_info.short_name
  }else if(btn_id==3){
    var url = '/pages/jgs/jg_addr/jg_addr?jg_id=' + that.jg_id + '&province=' + that.data.jg_info.province + '&city=' + that.data.jg_info.city + '&area=' + that.data.jg_info.area  + '&addr=' + that.data.jg_info.addr
  }else if(btn_id==4){
    var url = '/pages/jgs/jg_coordinate/jg_coordinate?jg_id=' + that.jg_id
  }else if(btn_id==5){
    var url = '/pages/jgs/jg_logo/jg_logo?jg_id=' + that.jg_id + '&jg_logo=' + that.data.jg_info.jg_logo
  }else if(btn_id==6){
    var url = '/pages/jgs/jg_job/jg_job?jg_id=' + that.jg_id
  }else if(btn_id==7){
    var url = '/pages/jgs/jg_pics/jg_pics?jg_id=' + that.jg_id
  }else if(btn_id==8){
    var url = '/pages/jgs/mana_jg_pics/mana_jg_pics?jg_id=' + that.jg_id
  }else if(btn_id==9){
    var url = '/pages/jgs/jg_uavType/jg_uavType?jg_id=' + that.jg_id
  }
  wx.navigateTo({
    url: url,
  })
}


  // 更新机构功能按钮点击次数
const update_jg_btn_count=(that,btn_id)=>{
    wx.request({
      url: domainName + '/update_jg_btn_count',
      data: {
        btn_id:btn_id
      },...parameter,
      success: res => {
        if(res.data.update_res){
          console.log('完成')
        }
      },
    })
  }


Page({

  /**
   * 页面的初始数据
   */
  data: {
    icon_url:oss_domain + 'static/picture/app_icon/',
    jg_info_hide:false,
    windowWidth:wx.getSystemInfoSync().windowWidth,

  },

  pre_view_jg_page(){
    getApp().get_vibration()
    wx.navigateTo({
      url: '/pages/jg_page/jg_page?jg_id=' + this.jg_id,
    })
  },


  operation_btn(e){
    getApp().get_vibration()
    operation_btn(this,e)
  },



  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    
    this.jg_id = options.jg_id
    jg_homePage_init(this,this.jg_id)
  },

  onHide(){
    this.can_onShow = true
  },

  onShow(){
    if(this.can_onShow){
      jg_homePage_init(this,this.jg_id)
    }
  },

})